package com.itheima.admin.controller;


import com.itheima.PageVo;
import com.itheima.Result;
import com.itheima.admin.dto.ModuleDto;
import com.itheima.admin.dto.PageDto;
import com.itheima.admin.service.IModuleService;
import com.itheima.admin.vo.ModuleVo;
import com.itheima.admin.vo.ModuleVoAll;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/module")
@CrossOrigin
public class ModuleController {
    @Autowired
    private IModuleService imOduleService;

    @DeleteMapping("/{id}")
    public Result deleteModule(@PathVariable("id") String id) {
        boolean result = imOduleService.deleteModule(id);
        return new Result(result, null, result ? "删除用户成功" : "删除用户失败");
    }

    @PostMapping("/add")
    public Result addModule(@RequestBody ModuleDto moduleDto) {
        boolean result = imOduleService.addModule(moduleDto);
        return new Result(result, null, result ? "添加用户成功" : "添加用户失败");
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询用户")
    public ModuleVo queryById(@PathVariable("id") String id) {
        return imOduleService.queryById(id);
    }

    @PutMapping("/edit")
    public Result updateModule(@RequestBody ModuleDto moduleDto) {
        boolean result = imOduleService.updateModule(moduleDto);
        return new Result(result, null, result ? "修改模块成功" : "修改模块失败");

    }

    @PostMapping("/list")
    public PageVo<ModuleVo> queryByPage(@RequestBody PageDto pageDto) {

        return imOduleService.queryByPage(pageDto);
    }

    @GetMapping("/listall")
    public List<ModuleVoAll> selectAll(){
        return imOduleService.selectAll();
    }
}
